﻿using MySql.Data.MySqlClient;
using NB.MGJ.Common.Helper;
using NB.MGJ.Model;
using NB.MGJ.Model.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;


namespace NB.MGJ.Service
{
    public partial class ManagerService
    {
        #region 机构

        #region 手机端
        /// <summary>
        /// 获取当前机构直接子级机构
        /// </summary>
        /// <param name="enterpriseId"></param>
        /// <returns></returns>
        public IEnumerable<SelectItem> GetDirectSubLevel(int enterpriseId)
        {
            return _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(string.Format("SELECT ID,EnterpriseName FROM organization_enterprise WHERE HeadId ={0} AND ViewDel = 0 AND ViewFlag =1", enterpriseId)).Select(p =>
             {
                 return new SelectItem
                 {
                     Code = p.ID,
                     Name = p.EnterpriseName
                 };
             });
        }

        /// <summary>
        /// 获取当前机构直接上级机构
        /// </summary>
        public IEnumerable<SelectItem> GetDirectSuperior(int enterpriseId)
        {
            return _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(string.Format("SELECT ID,EnterpriseName FROM organization_enterprise WHERE ID = (SELECT HeadId FROM organization_enterprise WHERE ID= {0} AND ViewDel = 0 AND ViewFlag =1) AND ViewDel = 0 AND ViewFlag =1", enterpriseId)).Select(p =>
            {
                return new SelectItem
                {
                    Code = p.ID,
                    Name = p.EnterpriseName
                };
            });
        }

        #endregion

        #region 增

        public int AddEnterpriseService(Organization_Enterprise Enterprise)
        {
            try
            {
                int result = _baseRepository.InsertReturnID<Organization_Enterprise>(Enterprise);
                return result;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }









        public bool GetByEnterparise(string EnterpriseName)
        {
            //int dd = Convert.ToInt32(_baseRepository.GetSingle("SELECT COUNT(*) FROM Organization_Enterprise WHERE EnterpriseName='" + EnterpriseName+"' "));
            //bool result = dd > 0 ? false : true;
            //return result;
            int dd = Convert.ToInt32(_baseRepository.GetSingle("SELECT COUNT(1) FROM Organization_Enterprise WHERE EnterpriseName='" + EnterpriseName + "' "));
            return dd == 0;
        }

        #region 添加机构 角色新增

        /// <summary>
        /// 添加机构 角色新增
        /// </summary>
        /// <param name="Role"></param>
        /// <returns></returns>
        public int OrganAddRoleInfoService(Sys_Role Role)
        {
            int result = _baseRepository.InsertReturnID<Sys_Role>(Role);
            return result;
        }

        #endregion


        #region 添加机构 用户角色关联


        public int AddRoleUserInfoService(Sys_RoleUserInfo model)
        {
            return _baseRepository.Insert<Sys_RoleUserInfo>(model);
        }

        #endregion

        #endregion

        #region 删除
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="oeid">ButtonId</param>
        /// <returns></returns>
        public int DelOrganizationalService(int oeid)
        {
            Organization_Enterprise e = new Organization_Enterprise();
            e.ID = oeid;
            e.ViewDel = 1;

            return _baseRepository.Update<Organization_Enterprise>(e);

            //string sql = " select * from Organization_Enterprise where ButtonId=" + oeid;
            //Organization_Enterprise _query = _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(sql).FirstOrDefault();
            //_query.ViewDel = 1;
            //int result = _baseRepository.Update<Organization_Enterprise>(_query);
            //return result;
        }
        #endregion

        #region 改

        /// <summary>
        /// 编辑机构 sql
        /// </summary>
        /// <param name="Enterprise"></param>
        /// <returns></returns>
        public int updEnterpriseSQLService(Organization_Enterprise Enterprise)
        {

            #region 修改sql语句
            string sql = @"UPDATE Organization_Enterprise
                           SET  
                            `EnterpriseName` =@EnterpriseName,
                            `OrganizationForm` = @OrganizationForm,
                            `OrganizationId` = @OrganizationId,
                            `ProvinceId` = @ProvinceId,
                            `City` = @City,
                            `Region` = @Region,
                            `StartTime` = @StartTime,
                            `EndTime` = @EndTime,
                            `Img` =@Img,
                            `ViewFlag` = @ViewFlag,
                            `ChangeLoginID` = @ChangeLoginID,
                            `ChangeLoginName` =@ChangeLoginName,
                            `ChangeDate` = @ChangeDate,
                            `ClassifyId` =@ClassifyId,
                            `ServiceVersion` = @ServiceVersion,
                            Remark=@Remark,
                            PersonMobile=@PersonMobile,
                            PersonCharge=@PersonCharge,
                            Address=@Address
                           WHERE
                           	ID =@ID ";
            MySqlParameter[] sqlpar = { 
                                        new MySqlParameter("@EnterpriseName",Enterprise.EnterpriseName),
                                        new MySqlParameter("@OrganizationForm",Enterprise.OrganizationForm),
                                        new MySqlParameter("@OrganizationId",Enterprise.OrganizationId),
                                        new MySqlParameter("@ProvinceId",Enterprise.ProvinceId),
                                        new MySqlParameter("@City",Enterprise.City),
                                        new MySqlParameter("@Region",Enterprise.Region),
                                        new MySqlParameter("@StartTime",Enterprise.StartTime),
                                        new MySqlParameter("@EndTime",Enterprise.EndTime),
                                        new MySqlParameter("@ViewFlag",Enterprise.ViewFlag),
                                        new MySqlParameter("@ChangeLoginID",Enterprise.ChangeLoginID),
                                        new MySqlParameter("@ChangeDate",Enterprise.ChangeDate),
                                        new MySqlParameter("@ClassifyId",Enterprise.ClassifyId),
                                        new MySqlParameter("@ServiceVersion",Enterprise.ServiceVersion),
                                        new MySqlParameter("@Remark",Enterprise.Remark),
                                        new MySqlParameter("@PersonMobile",Enterprise.PersonMobile),
                                        new MySqlParameter("@PersonCharge",Enterprise.PersonCharge),
                                        new MySqlParameter("@Address",Enterprise.Address),
                                        new MySqlParameter("@Img",Enterprise.Img),
                                        new MySqlParameter("@ID",Enterprise.ID)
                                      };

            #endregion
            int result = _baseRepository.ExecuteSql<int>(sql, sqlpar);

            return result;

        }

        /// <summary>
        /// 编辑机构  update 底层方法
        /// </summary>
        /// <param name="Enterprise"></param>
        /// <returns></returns>
        public int updEnterpriseService(Organization_Enterprise Enterprise)
        {
            return _baseRepository.Update<Organization_Enterprise>(Enterprise);
        }

        #region 查询单个Model

        public Organization_Enterprise GetEnterpriseModelId(int id)
        {
            string sql = " select * from Organization_Enterprise where id=" + id;
            //  Organization_Enterprise _query = _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(sql).ToList().FirstOrDefault();
            var _query = _baseRepository.ExecuteText<Organization_Enterprise>(sql);
            return _query;

        }
        #endregion


        #region 下拉框绑定  形式  类型
        /// <summary>
        /// 
        /// </summary>
        /// <param name="roleID">系统预定义角色</param>
        /// <returns></returns>
        public List<Organization_Form> GetFormBoxService(int roleID)
        {
            string sql = string.Format(" select distinct f.id,name from  Organization_FormTypeRole o  left join Organization_Form f  on o.OrganizationFormId=f.ID  where o.RoleId={0} and name is not NULL", roleID);
            IEnumerable<Organization_Form> _query = _baseRepository.ExecuteSqlCollection<Organization_Form>(sql);
            return _query.ToList();
        }

        public List<Organization_Type> GetTypeService(int roleID, int formID)
        {
            string sql = string.Format(@"select distinct t.name,t.id,o.JuniorRole from   Organization_FormTypeRole o  left join Organization_Type t  on o.OrganizationTypeId=t.ID   where o.RoleId in ({0}) and o.OrganizationFormId={1}  and JuniorRole!=-1 ", roleID, formID);
            IEnumerable<Organization_Type> _query = _baseRepository.ExecuteSqlCollection<Organization_Type>(sql);
            return _query.ToList();
        }

        #endregion

        #endregion

        #region 查

        public V_Organization OrganizationalShowDataId(int id)
        {
            string sql = "SELECT * FROM V_Organization where ID=" + id;
            var result = _baseRepository.ExecuteSqlCollection<V_Organization>(sql).FirstOrDefault();
            return result;
        }

        #region 导出查询
        public IEnumerable<V_Organization> GetAllOrganization(string where, string key)
        {
            var rs = "SELECT * FROM v_organizationenterprise where " + where;

            return _baseRepository.ExecuteSqlCollection<V_Organization>(rs);
        }
        #endregion

        #region 分页数据
        /// <summary>
        /// 分页数据
        /// </summary>
        /// <param name="model"></param>
        /// <param name="pager"></param>
        /// <returns></returns>
        public PagedList<V_Organization> GetOrganizationalInfoService(ref PagerModel pager, string Osearch)
        {
            #region Sql查询

            StringBuilder strSql1 = new StringBuilder();
            //mysql 不支持换行
            strSql1.Append(@" 	organization_enterprise e
                                LEFT JOIN Sys_Region r
                                on e.ProvinceId=r.codeID
                                LEFT JOIN Organization_Type t
                                on e.OrganizationId=t.ID
                                left JOIN organization_form f
                                on e.OrganizationForm=f.ID");

            var strSql = new StringBuilder(strSql1.ToString().Trim(','));
            pager.FldName = @" 	e.ID,
	                            CODE,
	                            EnterpriseName,
                                f.`Name` as fName,
                                t.`Name` as tName,
	                            (select EnterpriseName from organization_enterprise et where e.SuperiorsOrganization=et.ID) as SuperiorsOrganizationName,
	                            PersonCharge,
	                            PersonMobile,
	                            LandlinePhone,
	                            ViewFlag,
	                            (select name from sys_region r where e.ProvinceId=r.codeID ) as PrivinceName,
	                            (select name from sys_region r where e.City=r.codeID ) as CityName,
	                            (select name from sys_region r where e.Region=r.codeID ) as RegionName,
	                            Address,
	                            CreateDate ";

            
            pager.TblName = strSql.ToString();

            if (string.IsNullOrWhiteSpace(pager.StrCondition))
            {
                pager.StrCondition = " 1=1 ";
            }
         
            
            if (string.IsNullOrWhiteSpace(pager.FldSort))
            {
                pager.FldSort = "  e.ChangeDate desc ";
            }

            #endregion
            MySqlParameter[] parameters = _baseRepository.SqParameterRefactor(ref pager);
            IEnumerable<V_Organization> resultList = _baseRepository.ExecuteStoredProcedureCollection<V_Organization>("Common_PageList", parameters);
            return new PagedList<V_Organization>(resultList.ToList(), pager.Page, pager.PageSize, 1, Convert.ToInt32(parameters[6].Value));
        }

        #region 查询organization_formtyperole 根据机构形式 类型 返回角色ID
        public int GetRoleID(int Fid, int Eid, string roleid)
        {
            string sql = string.Format(" select JuniorRole from organization_formtyperole where OrganizationFormId={0} and  OrganizationTypeId={1} and roleid in ({2}) ", Fid, Eid, roleid);
            int rid = Convert.ToInt32(_baseRepository.GetSingle(sql));
            return rid;
        }
        #endregion



        public List<ServiceVersion> GetServersionList()
        {




            var str = "[{\"Key\":0,\"Value\":\"防伪\",\"Bind\":31},{\"Key\":1,\"Value\":\"溯源标准版\",\"Bind\":32},{\"Key\":2,\"Value\":\"溯源黄金版\",\"Bind\":33},{\"Key\":3,\"Value\":\"溯源钻石版\",\"Bind\":35},{\"Key\":4,\"Value\":\"窜货\",\"Bind\":36},{\"Key\":5,\"Value\":\"营销\",\"Bind\":37}]";


            List<ServiceVersion> list = new List<ServiceVersion>();
            list = JSONStringToList<ServiceVersion>(str);

            return list;

        }

        public static List<T> JSONStringToList<T>(string JsonStr)
        {
            JavaScriptSerializer Serializer = new JavaScriptSerializer();
            //设置转化JSON格式时字段长度
            List<T> objs = Serializer.Deserialize<List<T>>(JsonStr);
            return objs;
        }


        public List<ServiceVersion> GetServiceListByRoleIdListStr(string roleIds)
        {

            List<ServiceVersion> svList = new List<ServiceVersion>();
            var alllist = GetServersionList();
            if (roleIds == null)
            {
                return alllist;
            }
            string[] key = roleIds.Split(',');


            for (int i = 0; i < key.Length; i++)
            {
                foreach (var item in alllist)
                {
                    if (item.Key == Convert.ToInt32(key[i]))
                    {
                        svList.Add(item);
                    }
                }
            }

            return svList;
        }


        #endregion
        public int GetRoleIdByVersion(string version)
        {
            switch (version)
            {
                case "0":
                    return 31;

                case "1":
                    return 32;

                case "2":
                    return 33;

                case "3":
                    return 35;

                case "4":
                    return 36;

                case "5":
                    return 37;

                default:
                    return 0;

            }
        }

        public List<int> GetRoleIdByKey(string roleKey)
        {

            string[] key = roleKey.Split(',');

            List<int> roleIds = new List<int>();

            for (int i = 0; i < key.Length; i++)
            {
                roleIds.Add(GetRoleIdByVersion(key[i]));
            }

            return roleIds;
        }



        #region 获取单个Model

        public Organization_Enterprise GetEnterpriseModel(string code)
        {
            string sql = " select * from organization_enterprise where Code='" + code + "'";
            return _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(sql).FirstOrDefault();
        }


        public Organization_Enterprise GetEnterpriseModel_Eid(int eid)
        {
            string sql = " select * from organization_enterprise where id=" + eid;
            return _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(sql).FirstOrDefault();
        }


        #endregion

        #region 获取所有总部（不包含本机构）
        public List<Organization_Enterprise> GetSonEnterprise(int eid)
        {
            try
            {
                string sql = "";
                if (eid == 1)
                {
                    sql = "select * from  organization_enterprise where ViewDel=0 and headid=1";
                }
                else
                {
                    string sonEnterprise = GetSonEnterpriseStrArray(eid);
                    sql = "select * from  organization_enterprise where ViewDel=0 and SuperiorsOrganization in (" + sonEnterprise + ") or ID in (" + sonEnterprise + ")";
                }
                List<Organization_Enterprise> list = _baseRepository.ExecuteSqlCollection<Organization_Enterprise>(sql, null).ToList();
                return list;
            }
            catch (Exception ex)
            {

                throw ex;
            }


        }


        public string GetSonEnterpriseStrArray(int eid)
        {
            string sql = string.Format("select getJuniorEnterprise({0})", eid);
            return _baseRepository.GetSingle(sql).ToString();
        }

        #endregion

        #region 获取机构形式
        /// <summary>
        /// 获取机构形式名称
        /// </summary>
        /// <param name="formid">形式ID</param>
        /// <returns></returns>
        public string GetEnterpriseForm(int formid)
        {
            string sql = " select Name from Organization_Form where ID=" + formid;
            return _baseRepository.ExecuteText<Organization_Form>(sql).Name;
        }
        #endregion

        #endregion

        #endregion

        public bool GetEModel(string eName, int id)
        {
            bool IsExist = true;
            string sql = "select * from Organization_Enterprise where ViewDel=0 and EnterpriseName='{0}'";
            if (id != 0) sql += " and id!=" + id;
            var model = _baseRepository.ExecuteSql<Organization_Enterprise>(string.Format(sql, eName));
            if (model != null) IsExist = false;
            return IsExist;
        }


        #region 权限设置

        #region 获取菜单表格

        /// <summary>
        /// 获取菜单表格
        /// </summary>
        public List<Sys_Menu> GetTableTreeService(int uid)
        {
            string sqlList = " select Rid from Sys_RoleUserInfo ru LEFT JOIN sys_role r on ru.Rid=r.ID where ru.uId=" + uid;
            string where = string.Join(",", _baseRepository.ExecuteSqlCollection<Sys_RoleUserInfo>(sqlList).Select(b => b.Rid));
            string sql = uid == 1 ?
                "select DISTINCT ID,ParentId,MenuName,StatusID,isParent from Sys_Menu where MenuName not in('菜单管理' ) "
                : @"select  DISTINCT m.ID,ParentId,MenuName,StatusID,isParent   from Sys_MenuRoleInfo mr 
                    left join sys_role s on mr.Rid=s.ID
                    left join Sys_Menu  m on m.ID=mr.MenuID where rid in (" + where + ") and MenuName is not null";
            return _baseRepository.ExecuteSqlCollection<Sys_Menu>(sql).ToList();
        }
        #endregion

        #region 给当前角色赋值
        public List<sys_MenuRoleInfo> GetRoleTreeService(int Rid)
        {
            string sql = "select * from Sys_MenuRoleInfo where Rid=" + Rid;
            List<sys_MenuRoleInfo> lsit = _baseRepository.ExecuteSqlCollection<sys_MenuRoleInfo>(sql).ToList();
            return lsit;
        }
        #endregion

        #region 添加角色菜单关联
        public int AddMenuRoleInfoService(sys_MenuRoleInfo model)
        {
            return _baseRepository.Insert<sys_MenuRoleInfo>(model);
        }
        public void AddMenuRoleInfoService(List<sys_MenuRoleInfo> model, int Id)
        {
            string _sql = "INSERT INTO sys_menuroleinfo(Rid,MenuID,IsAdd,IsDel,IsUpd,Extension1,Extension2) VALUES {0}";
            string _values = string.Empty;
            if (model != null)
            {
                foreach (var item in model)
                {
                    _values += string.Format("({0},{1},{2},{3},{4},{5},{6}),", Id, item.MenuID, item.IsAdd, item.IsDel, item.IsUpd, item.Extension1 ?? "NULL", item.Extension2 ?? "NULL");
                }
                _values = _values.TrimEnd(',');
                _sql = string.Format(_sql, _values);
                _baseRepository.ExecuteSql<int>(_sql);
            }
        }
        #endregion

        #region 修改角色权限
        /// <summary>
        /// 修改角色权限
        /// </summary>
        /// <param name="model">sys_MenuRoleInfo</param>
        /// <returns>1||0</returns>
        public int UpdMenuRole(sys_MenuRoleInfo model)
        {
            return _baseRepository.Update<sys_MenuRoleInfo>(model);
        }
        #endregion

        #region 判断该角色权限 该角色ID 菜单ID 是否存在

        //public bool IsMenuRoleInfo(int menuID,int rId) 
        //{
        //    string sql =string.Format( " select ButtonId from Sys_MenuRoleInfo where Rid={0} and MenuID={1} ",rId,menuID);
        //    return _baseRepository.Exists(sql);
        //}
        #endregion

        #region 根据机构编码获取机构信息
        public Organization_Enterprise GetInfoByCodeModel(string code)
        {
            Organization_Enterprise model = new Organization_Enterprise();
            string sql = string.Format(@"select * from Organization_Enterprise where code={0}", code);
            Common.WeiXinHelper.WriteLog("sql", sql.ToString());
            return _baseRepository.ExecuteText<Organization_Enterprise>(sql);
        }
        #endregion

        #endregion


        #region  新增后修改用户机构code  修改用户机构id


        /// <summary>
        /// 改变用户的机构ID
        /// </summary>
        /// <param name="EID"></param>
        /// <param name="userId"></param>
        /// <returns></returns>
        public int updateUserEID(int EID, int userId)
        {
            var sql = "update sys_user set EnterpriseId=" + EID + " where ID=" + userId;
            var result = _baseRepository.ExecuteSql<int>(sql);
            return result;
        }

        /// <summary>
        /// 将机构ID改为试用机构ID
        /// </summary>
        /// <param name="EID"></param>
        /// <returns></returns>
        public int updateEnterpriseIdToTryOut(int EID)
        {
            var tryoutEID = Convert.ToInt32(EID.ToString().PadRight(5, '0'));
            var code = EID.ToString().PadRight(5, '0');
            //return baseRepository2.Update<L.EntityModel.Organization_Enterprise>(p => p.ID == EID, p =>
            //{
            //    p.Code =code;
            //    p.ID =tryoutEID;
            //});
            #region MyRegion
            var sql = "update organization_enterprise set ID=" + tryoutEID + " ,Code=" + code + " where ID=" + EID;
            var result = _baseRepository.ExecuteSql<int>(sql);
            return result;
            #endregion
           
        }




        public int UpdateEnterpriseIdAndCode(Organization_Enterprise model)
        {
            //return baseRepository2.Update<L.EntityModel.Organization_Enterprise>(p => p.ID == model.OldId, p =>
            //{
            //    p.Code = model.Code;             
            //    p.ID = model.ID;
            //});

            #region MyRegion
            var sql = "update organization_enterprise set id=" + model.ID + " ,code='" + model.Code + "' where id=" + model.OldId;
            var result = _baseRepository.ExecuteSql<int>(sql);
            return result; 
            #endregion
        }
        /// <summary>
        /// 获取子机构排序码
        /// </summary>
        /// <param name="EID"></param>
        /// <returns></returns>
        public string GetNewChildCodeByEID(int? EID)
        {
            int result = 1;
            var sql = "select count(*) as count  from organization_enterprise where HeadId=" + EID;
            var obj = _baseRepository.GetSingle(sql);
            if (!(Object.Equals(obj, null)))
            {
                result = Convert.ToInt32(obj.ToString()) + 1;
            }

            return result.ToString().PadLeft(4, '0');
        }










        /// <summary>
        /// 设置机构总部id
        /// </summary>
        /// <param name="child">被创建的机构</param>
        /// <param name="Create">创建者机构</param>
        public void SetEnterpriseHeadId(Organization_Enterprise child, Organization_Enterprise Create)
        {
            //如果创建者为诺标总部账号,则总部ID为1
            if (Create.ID == 1)
            {
                child.HeadId = 1;
            }
            //如果创建者不是诺标,则可能是  企业总部， 企业子机构
            else if (Create.ID != 1)
            {
                //企业总部的总部ID为1 则该机构是企业总部，企业总部创建的子机构的总部ID为  企业总部ID
                if (Create.HeadId == 1)
                {
                    child.HeadId = Create.ID;

                }
                //
                else if (Create.HeadId != 1 && Create.HeadId != 0)
                {
                    child.HeadId = Create.HeadId;
                }

            }

        }



        /// <summary>
        /// 
        /// </summary>
        /// <param name="Enterprise"></param>
        /// <param name="Type">0 新建总部  1 新建子机构</param>
        /// <returns></returns>
        public int GetEIDInType(int Type)
        {
            int result = 0;
            var sql = "";
            if (Type == 0)
            {
                sql = "select max(ID) from organization_enterprise where ID<10000";
            }
            else
            {
                sql = "select max(ID) from organization_enterprise where ID>10000";
            }

            var obj = _baseRepository.GetSingle(sql);
            if (!(Object.Equals(obj, null)))
            {
                result = Convert.ToInt32(obj.ToString()) + 1;
            }
            return result;
        }


        /// <summary>
        /// 创建机构的后续操作
        /// </summary>
        /// <param name="model">被创建的机构</param>
        /// <param name="CreateModel">创建者机构</param>
        /// <returns></returns>
        public int UpdateEnterpriseAfterCreate(Organization_Enterprise model, Organization_Enterprise CreateModel)
        {

            model.OldId = model.ID;

            //设置机构总部ID【一定要在修改机构码之前设置总部机构ID】
            SetEnterpriseHeadId(model, CreateModel);

            //当创建者机构为诺标时   id为0001~9999 自增
            if (CreateModel.ID == 1)
            {
                model.ID = GetEIDInType(0);
                model.Code = model.ID.ToString().PadLeft(4, '0');
            }

            //当创建者机构非诺标时  id为  总部ID+4位序列号
            if (CreateModel.ID != 1)
            {
                model.StartTime = CreateModel.StartTime;
                model.EndTime = CreateModel.EndTime;

                //根据该机构的总部机构ID，获取该机构总部下机构数量，得到机构序号
                string SortCode = GetNewChildCodeByEID(model.HeadId);

                model.ID = Convert.ToInt32((model.HeadId.ToString()) + SortCode);
                model.Code = model.HeadId.ToString().PadLeft(4, '0') + SortCode;

            }

            var result = UpdateEnterpriseIdAndCode(model);
            //修改id后，更新model（目前只为更新开始时间和结束时间）
            updEnterpriseService(model);

            return result;
        }





        #endregion

        //public int Update 


        #region 根据
        #endregion





    }


}
